<div class="float_left">
  <h2>Listing books</h2>
</div>
<div class="float_right">
<% form_tag(:controller => 'books', :action => 'search') do %>
    <%= text_field_tag :isbn %> <br/> <%= submit_tag 'Search by ISBN' %>
<% end %>
</div>
<table>
  <tr>
    <th>Barcode</th>
    <th>Title</th>
    <th>Description</th>
    <th>Image</th>
    <th>ISBN</th>
  </tr>

<% @books.each do |book| %>
  <tr>
    <td class="code"><%=h book.barcode %></td>
    <td class="title"><%=h book.title %></td>
    <td class="desc"><%=h book.description %></td>
    <td class="img"><%= image_tag book.image_url %></td>
    <td><%=h book.ISBN %><br />
    <% if User.find(session[:user_id]).is_admin %>
      <%= link_to 'Show', book %><br />
      <%= link_to 'Edit', edit_book_path(book) %><br />
      <%= link_to 'Destroy', book, :confirm => 'Are you sure?', :method => :delete %><br />
    <% else %>
      <% if books_cant_borrow.include?(book) == false %>
        <%= link_to 'Borrow', :controller => "books", :action => "create_request", :id => book.id %>
      <% end %>
      <% if books_cant_borrow.include?(book) && books_cant_reserve.include?(book) == false %>
        <%= link_to 'Reserve', :controller => "books", :action => "create_reserve", :id => book.id %>
      <% end %>
      <% if borrowed_books.include?(book) %>
        <%= link_to 'Renew', :controller => "books", :action => "create_renew", :id => book.id %>
        <%= link_to 'Return', :controller => "books", :action => "create_return", :id => book.id %>
      <% end %>
    <% end %>
    </td>
  </tr>
<% end %>
</table>

<br />

<% if User.find(session[:user_id]).is_admin %>
  <%= link_to 'New book', new_book_path %>
<% end %>
